package utils;

import core.Phone2;
import weka.clusterers.ClusterEvaluation;
import weka.clusterers.SimpleKMeans;
import weka.core.Instance;
import weka.core.Instances;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: lahiru
 * Date: 4/23/14
 * Time: 4:41 PM
 * To change this template use File | Settings | File Templates.
 */
public class WekaClustering {

    private static final String clusterFileLocation = "/home/lahiru/experiments/Speaker-effects/clustering/";
    private static double averageGlobalSimilarity = 0.0;
    private static double averageGlobalPlaceSimilarity = 0.0;
    private static double averageGlobalMannerSimilarity = 0.0;
    private static double averageGlobalVoicednessSimilarity = 0.0;

    public enum Place {
        FRONTVOWEL, CENTRALVOWEL, BACKVOWEL, CORONAL, PALATAL, LABIAL, VELAR, SILENCE, OTHER
    }

    public enum Manner {
        HIGHVOWEL, MIDVOWEL, LOWVOWEL, FRICATIVE, NASAL, STOPCONS, APPROXIMANT, SILENCE, OTHER
    }

    public enum Voicedness {
        VOICED, UNVOICED, SILENCE
    }

    private static Map<Integer, ArrayList<Integer>> similarityVectors = new HashMap<Integer, ArrayList<Integer>>();
    private static Map<Integer, ArrayList<Integer>> placeSimilarityVectors = new HashMap<Integer, ArrayList<Integer>>();
    private static Map<Integer, ArrayList<Integer>> mannerSimilarityVectors = new HashMap<Integer, ArrayList<Integer>>();
    private static Map<Integer, ArrayList<Integer>> voicednessSimilarityVectors = new HashMap<Integer, ArrayList<Integer>>();


    public static void assignSubPhoneticFeatures() {

        //Map id phone
        Map<Integer, Phone2> phoneMap = new HashMap<Integer, Phone2>();
        //Map id, similarityVector
//        Map<Integer, ArrayList<Integer>> similarityVectors = new HashMap<Integer, ArrayList<Integer>>();


        Phone2 p0 = new Phone2(0, Place.SILENCE, Manner.SILENCE, Voicedness.SILENCE);       //sil
        Phone2 p1 = new Phone2(1, Place.OTHER, Manner.OTHER, Voicedness.VOICED);            //spn
        Phone2 p2 = new Phone2(2, Place.SILENCE, Manner.SILENCE, Voicedness.VOICED);          //nsn
        Phone2 p3 = new Phone2(3, Place.CORONAL, Manner.FRICATIVE, Voicedness.UNVOICED);    //s
        Phone2 p4 = new Phone2(4, Place.BACKVOWEL, Manner.HIGHVOWEL, Voicedness.VOICED);    //uw
        Phone2 p5 = new Phone2(5, Place.CORONAL, Manner.STOPCONS, Voicedness.UNVOICED);    //t
        Phone2 p6 = new Phone2(6, Place.VELAR, Manner.NASAL, Voicedness.VOICED);    //n
        Phone2 p7 = new Phone2(7, Place.VELAR, Manner.STOPCONS, Voicedness.UNVOICED);    //k
        Phone2 p8 = new Phone2(8, Place.FRONTVOWEL, Manner.APPROXIMANT, Voicedness.VOICED);    //y
        Phone2 p9 = new Phone2(9, Place.CORONAL, Manner.FRICATIVE, Voicedness.VOICED);    //z
        Phone2 p10 = new Phone2(10, Place.BACKVOWEL, Manner.LOWVOWEL, Voicedness.VOICED);    //ao
        Phone2 p11 = new Phone2(11, Place.BACKVOWEL, Manner.LOWVOWEL, Voicedness.VOICED);    //ay
        Phone2 p12 = new Phone2(12, Place.PALATAL, Manner.FRICATIVE, Voicedness.UNVOICED);    //sh
        Phone2 p13 = new Phone2(13, Place.LABIAL, Manner.APPROXIMANT, Voicedness.VOICED);    //w
        Phone2 p14 = new Phone2(14, Place.VELAR, Manner.NASAL, Voicedness.VOICED);    //ng
        Phone2 p15 = new Phone2(15, Place.FRONTVOWEL, Manner.MIDVOWEL, Voicedness.VOICED);    //ey
        Phone2 p16 = new Phone2(16, Place.LABIAL, Manner.STOPCONS, Voicedness.VOICED);    //b
        Phone2 p17 = new Phone2(17, Place.PALATAL, Manner.FRICATIVE, Voicedness.UNVOICED);    //ch
        Phone2 p18 = new Phone2(18, Place.BACKVOWEL, Manner.LOWVOWEL, Voicedness.VOICED);    //oy
        Phone2 p19 = new Phone2(19, Place.PALATAL, Manner.FRICATIVE, Voicedness.VOICED);    //jh
        Phone2 p20 = new Phone2(20, Place.CORONAL, Manner.STOPCONS, Voicedness.VOICED);    //d
        Phone2 p21 = new Phone2(21, Place.PALATAL, Manner.FRICATIVE, Voicedness.VOICED); //zh
        Phone2 p22 = new Phone2(22, Place.VELAR, Manner.STOPCONS, Voicedness.VOICED);   //g
        Phone2 p23 = new Phone2(23, Place.BACKVOWEL, Manner.HIGHVOWEL, Voicedness.VOICED);   //uh
        Phone2 p24 = new Phone2(24, Place.LABIAL, Manner.FRICATIVE, Voicedness.UNVOICED);   //f
        Phone2 p25 = new Phone2(25, Place.LABIAL, Manner.FRICATIVE, Voicedness.VOICED);   //v
        Phone2 p26 = new Phone2(26, Place.CENTRALVOWEL, Manner.MIDVOWEL, Voicedness.VOICED);   //er
        Phone2 p27 = new Phone2(27, Place.BACKVOWEL, Manner.LOWVOWEL, Voicedness.VOICED);   //aa
        Phone2 p28 = new Phone2(28, Place.FRONTVOWEL, Manner.HIGHVOWEL, Voicedness.VOICED);   //IH
        Phone2 p29 = new Phone2(29, Place.LABIAL, Manner.NASAL, Voicedness.VOICED);   //m
        Phone2 p30 = new Phone2(30, Place.CORONAL, Manner.FRICATIVE, Voicedness.VOICED);   //dh
        Phone2 p31 = new Phone2(31, Place.CORONAL, Manner.APPROXIMANT, Voicedness.VOICED);   //l
        Phone2 p32 = new Phone2(32, Place.CENTRALVOWEL, Manner.MIDVOWEL, Voicedness.VOICED);   //ah
        Phone2 p33 = new Phone2(33, Place.LABIAL, Manner.STOPCONS, Voicedness.UNVOICED);   //p
        Phone2 p34 = new Phone2(34, Place.BACKVOWEL, Manner.MIDVOWEL, Voicedness.VOICED);   //ow
        Phone2 p35 = new Phone2(35, Place.FRONTVOWEL, Manner.LOWVOWEL, Voicedness.VOICED);   //aw
        Phone2 p36 = new Phone2(36, Place.CENTRALVOWEL, Manner.FRICATIVE, Voicedness.UNVOICED);   //hh
        Phone2 p37 = new Phone2(37, Place.FRONTVOWEL, Manner.LOWVOWEL, Voicedness.VOICED);   //ae
        Phone2 p38 = new Phone2(38, Place.CORONAL, Manner.APPROXIMANT, Voicedness.VOICED);   //r
        Phone2 p39 = new Phone2(39, Place.CORONAL, Manner.FRICATIVE, Voicedness.UNVOICED);   //th
        Phone2 p40 = new Phone2(40, Place.FRONTVOWEL, Manner.HIGHVOWEL, Voicedness.VOICED);   //iy
        Phone2 p41 = new Phone2(41, Place.FRONTVOWEL, Manner.MIDVOWEL, Voicedness.VOICED);   //eh

        phoneMap.put(0, p0);
        phoneMap.put(1, p1);
        phoneMap.put(2, p2);
        phoneMap.put(3, p3);
        phoneMap.put(4, p4);
        phoneMap.put(5, p5);
        phoneMap.put(6, p6);
        phoneMap.put(7, p7);
        phoneMap.put(8, p8);
        phoneMap.put(9, p9);
        phoneMap.put(10, p10);
        phoneMap.put(11, p11);
        phoneMap.put(12, p12);
        phoneMap.put(13, p13);
        phoneMap.put(14, p14);
        phoneMap.put(15, p15);
        phoneMap.put(16, p16);
        phoneMap.put(17, p17);
        phoneMap.put(18, p18);
        phoneMap.put(19, p19);
        phoneMap.put(20, p20);
        phoneMap.put(21, p21);
        phoneMap.put(22, p22);
        phoneMap.put(23, p23);
        phoneMap.put(24, p24);
        phoneMap.put(25, p25);
        phoneMap.put(26, p26);
        phoneMap.put(27, p27);
        phoneMap.put(28, p28);
        phoneMap.put(29, p29);
        phoneMap.put(30, p30);
        phoneMap.put(31, p31);
        phoneMap.put(32, p32);
        phoneMap.put(33, p33);
        phoneMap.put(34, p34);
        phoneMap.put(35, p35);
        phoneMap.put(36, p36);
        phoneMap.put(37, p37);
        phoneMap.put(38, p38);
        phoneMap.put(39, p39);
        phoneMap.put(40, p40);
        phoneMap.put(41, p41);

        int numPhones = phoneMap.size();
        for (int i = 0; i < numPhones; i++) {
            ArrayList<Integer> similarityVector = new ArrayList<Integer>(numPhones);
            ArrayList<Integer> placeSimilarityVector = new ArrayList<Integer>(numPhones);
            ArrayList<Integer> mannerSimilarityVector = new ArrayList<Integer>(numPhones);
            ArrayList<Integer> voicednessSimilarityVector = new ArrayList<Integer>(numPhones);


            for (int j = 0; j < numPhones; j++) {
                int placeSimilarity = getPlaceSimilarity(phoneMap.get(i), phoneMap.get(j));
                int mannerSimilarity = getMannerSimilarity(phoneMap.get(i), phoneMap.get(j));
                int voicednessSimilarity = getVoicednessSimilarity(phoneMap.get(i), phoneMap.get(j));


                similarityVector.add(placeSimilarity + mannerSimilarity + voicednessSimilarity);
                placeSimilarityVector.add(placeSimilarity);
                mannerSimilarityVector.add(mannerSimilarity);
                voicednessSimilarityVector.add(voicednessSimilarity);
            }
            similarityVectors.put(i, similarityVector);
            placeSimilarityVectors.put(i, placeSimilarityVector);
            mannerSimilarityVectors.put(i, mannerSimilarityVector);
            voicednessSimilarityVectors.put(i, voicednessSimilarityVector);
        }
    }

    private static int getPlaceSimilarity(Phone2 p0, Phone2 p1) {
        int similarity = 0;
        if (p0.getPlace() == p1.getPlace()) {
            similarity = similarity + 1;
        }
        return similarity;
    }

    private static int getMannerSimilarity(Phone2 p0, Phone2 p1) {
        int similarity = 0;

        if (p0.getManner() == p1.getManner()) {
            similarity = similarity + 1;
        }


        return similarity;
    }

    private static int getVoicednessSimilarity(Phone2 p0, Phone2 p1) {
        int similarity = 0;

        if (p0.getVoicedness() == p1.getVoicedness()) {
            similarity = similarity + 1;
        }
        return similarity;  //To change body of created methods use File | Settings | File Templates.
    }

    /**
     * Run clusterers
     *
     * @param filename the name of the ARFF file to run on
     */
    public WekaClustering(String filename) throws Exception {
        ClusterEvaluation eval;
        Instances data;
//        String[]                options;
//        DensityBasedClusterer cl;
        Map<Integer, ArrayList<Double>> interDistances = new HashMap<Integer, ArrayList<Double>>();

        data = new Instances(new BufferedReader(new FileReader(filename)));


        //Calculate the distances between instances
        int numInstances = data.numInstances();
        for (int i = 0; i < numInstances; i++) {

            //calculate the distance vector for the current instance
            ArrayList<Double> distanceVector = new ArrayList<Double>(numInstances);
            for (int j = 0; j < numInstances; j++) {
                distanceVector.add(j, calculateDistance(data.instance(i), data.instance(j)));
            }
            interDistances.put(i, distanceVector);
        }
        // Kmeans
        double max=0.0;
        int maxcluser = 0;
        for(int i=2; i<=data.numInstances();i++){
//        for (int i = 1; i <= 30; i++) {                          //Assume number of clusters (k) > 1
            SimpleKMeans cl1 = new SimpleKMeans();
            cl1.setNumClusters(i);
            cl1.buildClusterer(data);
            eval = new ClusterEvaluation();
            eval.setClusterer(cl1);
            eval.evaluateClusterer(new Instances(data));
            double silp = calculateSilhouetteCoefficient(eval, data, interDistances);
            if (silp > max){
                max = silp;
                maxcluser = i;
            }
//            System.out.println(silp);
        }
        System.out.println("The max value " + max);
        System.out.println(" The optimum cluster " + maxcluser);


    }

    public static void clusteringForV(String filename, int numOfClusters, Map<Integer, String> phoneMapping) throws Exception {
        ClusterEvaluation eval;
        Instances data;

        data = new Instances(new BufferedReader(new FileReader(filename)));

        SimpleKMeans cl1 = new SimpleKMeans();
        cl1.setNumClusters(numOfClusters);
        cl1.buildClusterer(data);
        eval = new ClusterEvaluation();
        eval.setClusterer(cl1);
        eval.evaluateClusterer(new Instances(data));
        double[] clusterAssignments = eval.getClusterAssignments();
        Map<Integer, ArrayList<Integer>> clusters = new HashMap<Integer, ArrayList<Integer>>(numOfClusters);
        for (int i = 0; i < numOfClusters; i++) {
            clusters.put(i, new ArrayList<Integer>());
        }


        for (int i = 0; i < data.numInstances(); i++) {
            int clusterId = (int) clusterAssignments[i];
            clusters.get(clusterId).add(i);
//             clusters.put(i,clusters.get(clusterId).add(i));
        }

        double totalSimilarity = 0.0;
        double totalPlaceSimilarity = 0.0;
        double totalMannerSimilarity = 0.0;
        double totalVoicednessSimilarity = 0.0;
        for (int i : clusters.keySet()) {
            if (clusters.get(i).size() != 1) {
                double clusterSimilarity = calculateClusterSimilarity(clusters.get(i));
                double clusterPlaceSimilarity = calculateClusterPlaceSimilarity(clusters.get(i));
                double clusterMannerSimilarity = calculateClusterMannerSimilarity(clusters.get(i));
                double clusterVoicednessSimilarity = calculateClusterVoicednessSimilarity(clusters.get(i));
                totalSimilarity = totalSimilarity + ((clusterSimilarity - averageGlobalSimilarity) / Math.max(clusterSimilarity, averageGlobalSimilarity));
                totalPlaceSimilarity = totalPlaceSimilarity + ((clusterPlaceSimilarity - averageGlobalPlaceSimilarity) / Math.max(clusterPlaceSimilarity, averageGlobalPlaceSimilarity));
                totalMannerSimilarity = totalMannerSimilarity + ((clusterMannerSimilarity - averageGlobalMannerSimilarity) / Math.max(clusterMannerSimilarity, averageGlobalMannerSimilarity));
                totalVoicednessSimilarity = totalVoicednessSimilarity + ((clusterVoicednessSimilarity - averageGlobalVoicednessSimilarity) / Math.max(clusterVoicednessSimilarity, averageGlobalVoicednessSimilarity));
//                totalSimilarity = totalSimilarity + clusterSimilarity;
            } else {
                totalSimilarity = totalSimilarity + 1.0;
                totalPlaceSimilarity = totalPlaceSimilarity + 1.0;
                totalMannerSimilarity = totalMannerSimilarity + 1.0;
                totalVoicednessSimilarity = totalVoicednessSimilarity + 1.0;
//                totalSimilarity = totalSimilarity + 0.0;
            }

//            System.out.println("################# Cluster " + i + " ######################## " );
//
//            for(int k : clusters.get(i)){
//                System.out.print(phoneMapping.get(k) + " ");
//            }
//            System.out.println("\n");
        }
        System.out.println(totalSimilarity / numOfClusters +" " + totalPlaceSimilarity / numOfClusters + " " + totalMannerSimilarity / numOfClusters + " " + totalVoicednessSimilarity / numOfClusters);
//        System.out.println("The totalPlaceSimilarity   " + totalPlaceSimilarity / numOfClusters);
//        System.out.println("The totalMannerSimilarity   " + totalMannerSimilarity / numOfClusters);
//        System.out.println("The totalVoicednessSimilarity   " + totalVoicednessSimilarity / numOfClusters);
    }

    private static double calculateClusterSimilarity(ArrayList<Integer> integers) {
        int size = integers.size();
        int total = 0;
        int count = 0;
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                if (j < size) {
                    total = total + similarityVectors.get(i).get(j);
                    count = count + 1;
                }
            }
        }
        if (count == 0) {
            System.out.println("This cannot happen");
            return 0.0;
        } else {
            return (double) total / count;
        }
    }


    private static double calculateClusterPlaceSimilarity(ArrayList<Integer> integers) {
        int size = integers.size();
        int total = 0;
        int count = 0;
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                if (j < size) {
                    total = total + placeSimilarityVectors.get(i).get(j);
                    count = count + 1;
                }
            }
        }
        if (count == 0) {
            System.out.println("This cannot happen");
            return 0.0;
        } else {
            return (double) total / count;
        }
    }


    private static double calculateClusterMannerSimilarity(ArrayList<Integer> integers) {
        int size = integers.size();
        int total = 0;
        int count = 0;
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                if (j < size) {
                    total = total + mannerSimilarityVectors.get(i).get(j);
                    count = count + 1;
                }
            }
        }
        if (count == 0) {
            System.out.println("This cannot happen");
            return 0.0;
        } else {
            return (double) total / count;
        }
    }


    private static double calculateClusterVoicednessSimilarity(ArrayList<Integer> integers) {
        int size = integers.size();
        int total = 0;
        int count = 0;
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                if (j < size) {
                    total = total + voicednessSimilarityVectors.get(i).get(j);
                    count = count + 1;
                }
            }
        }
        if (count == 0) {
            System.out.println("This cannot happen");
            return 0.0;
        } else {
            return (double) total / count;
        }
    }

    private double calculateSilhouetteCoefficient(ClusterEvaluation eval, Instances data, Map<Integer, ArrayList<Double>> interDistances) {

        int numberOfClusters = eval.getNumClusters();
        double[] clusterAssignments = eval.getClusterAssignments();
        int numInstances = data.numInstances();
        double silhCoeff = 0.0;

        ArrayList<Integer> clusterMembers = new ArrayList<Integer>(numberOfClusters);

        for (int k = 0; k < numberOfClusters; k++) {  //initially all the cluster distances are set to zero.
            clusterMembers.add(0);
        }

        for (int i = 0; i < numInstances; i++) {
            int clusterId = (int) clusterAssignments[i];
            clusterMembers.set(clusterId, clusterMembers.get(clusterId) + 1);
        }


        for (int i = 0; i < numInstances; i++) {
            int clusterIdMain = (int) clusterAssignments[i];
            if (clusterMembers.get(clusterIdMain) != 1) {   // if the current instance is the only object in the cluster -> s(i) = 0
                ArrayList<Double> clusterDistances = new ArrayList<Double>(numberOfClusters); // keeps track of the cluster distances for the given point
                ArrayList<Double> distanceVector = interDistances.get(i);

                for (int k = 0; k < numberOfClusters; k++) {  //initially all the cluster distances are set to zero.
                    clusterDistances.add(0.0);
                }

                for (int j = 0; j < numInstances; j++) {
                    double distance = distanceVector.get(j);
                    int clusterId = (int) clusterAssignments[j];
                    clusterDistances.set(clusterId, clusterDistances.get(clusterId) + distance);
                }


                for (int k = 0; k < numberOfClusters; k++) {  //average the cluster distances
                    clusterDistances.set(k, (clusterDistances.get(k) / clusterMembers.get(k)));
                }

//
                List<Double> cDistanceList = new ArrayList<Double>(numberOfClusters - 1);
//             Double[] cDistances = new Double[numberOfClusters-1];
                for (int cId = 0; cId < numberOfClusters; cId++) {
                    if (cId != clusterIdMain) {
                        cDistanceList.add(clusterDistances.get(cId));
                    }
                }

                Object[] cDistances = cDistanceList.toArray();
                Arrays.sort(cDistances);


                double minAvgDistanceOther = 0.0;
                double minAvgDistanceOwn = clusterDistances.get(clusterIdMain);
                if (numberOfClusters == 1) {
                    minAvgDistanceOther = minAvgDistanceOwn;
                } else {
                    minAvgDistanceOther = (Double) cDistances[0];
                }
                double silhP = (minAvgDistanceOther - minAvgDistanceOwn) / Math.max(minAvgDistanceOther, minAvgDistanceOwn);
                silhCoeff += silhP;
            }
        }
        return silhCoeff / numInstances;  //To change body of created methods use File | Settings | File Templates.
    }

    private double calculateDistance(Instance instance, Instance instance1) {
        double distance = 0.0;
        for (int i = 0; i < instance.numAttributes(); i++) {
            double d = instance.value(i) - instance1.value(i);
            distance += d * d;
        }
        return Math.sqrt(distance);  //To change body of created methods use File | Settings | File Templates.
    }

    /**
     * usage:
     * ClusteringDemo arff-file
     */
    public static void main(String[] args) throws Exception {

        String filename = clusterFileLocation + "hiddenLayer1.arff";
        new utils.WekaClustering(filename);


        System.exit(0);

        assignSubPhoneticFeatures();
        int count = 0;
        int total = 0;
        int tPlace = 0;
        int tManner = 0;
        int tVoicedness = 0;
        int tempSize = similarityVectors.size();
        for (int i = 0; i < tempSize - 1; i++) {
            ArrayList<Integer> similarityVector = similarityVectors.get(i);
            ArrayList<Integer> placeSimilarityVector = placeSimilarityVectors.get(i);
            ArrayList<Integer> mannerSimilarityVector = mannerSimilarityVectors.get(i);
            ArrayList<Integer> voicednessSimilarityVector = voicednessSimilarityVectors.get(i);
            for (int j = i + 1; j < tempSize; j++) {
                total = total + similarityVector.get(j);
                tPlace = tPlace + placeSimilarityVector.get(j);
                tManner = tManner + mannerSimilarityVector.get(j);
                tVoicedness = tVoicedness + voicednessSimilarityVector.get(j);
                count = count + 1;
            }
        }

        averageGlobalSimilarity = (double) total / count;
        averageGlobalPlaceSimilarity = (double) tPlace / count;
        averageGlobalMannerSimilarity = (double) tManner / count;
        averageGlobalVoicednessSimilarity = (double) tVoicedness / count;

        Map<Integer, String> phoneMapping = new HashMap<Integer, String>();
        String phoneIdFile = "/media/Bunty/Academic/Research/speaker-effects/phonemeIDs";  //todo make this configurable
        try {
            BufferedReader mapBr = new BufferedReader(new FileReader(phoneIdFile));
            String line;
            while ((line = mapBr.readLine()) != null) {
                String phoneIds[] = line.split("\t");
                phoneMapping.put(Integer.parseInt(phoneIds[0]), phoneIds[1]);
            }

            mapBr.close();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


//        System.out.println("Clustering layer 1");
//        String filename = clusterFileLocation + "hiddenLayer1.arff";
//        clusteringForV(filename, 19, phoneMapping);
//
//        System.out.println("Clustering layer 2");
//        filename =  clusterFileLocation + "hiddenLayer2.arff";
//        clusteringForV(filename, 20, phoneMapping);
//
//        System.out.println("Clustering layer 3");
//        filename =  clusterFileLocation + "hiddenLayer3.arff";
//        clusteringForV(filename, 19, phoneMapping);
//
//        System.out.println("Clustering layer 4");
//        filename =  clusterFileLocation + "hiddenLayer4.arff";
//        clusteringForV(filename, 15, phoneMapping);
//
//        System.out.println("Clustering layer 5");
//        filename =  clusterFileLocation + "hiddenLayer5.arff";
//        clusteringForV(filename, 25, phoneMapping);
//
//        System.out.println("Clustering layer 6");
//        filename =  clusterFileLocation + "hiddenLayer6.arff";
//        clusteringForV(filename, 24, phoneMapping);
    }
}
